// JavaScript Document
//var emo;

$(document).on("ready", main);

function main() {
    dibuja_graf();
    $("a[rel^='prettyPhoto']").prettyPhoto();
    
}

function dibuja_graf() {
    $("#grafica").highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Resultados de tendencias de grupo'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>',
            //percentageDecimals: 1
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function() {
                        return '<b>' + this.point.name + '</b>: ' + this.percentage + ' %';
                    }
                }
            },
            series: {
                cursor: 'pointer',
                point: {
                    events: {
                        click: function() {
                            var emo = this.name;
                            //alert(emo);
                            crea_sesion(emo);
                            window.parent.$.prettyPhoto.changePage('next');
                        }
                    }
                }
            }
        },
        series: [{
                type: 'pie',
                name: 'Resultados del Análisis',
                data: [
                    ['Alegría', 45.0],
                    ['Tristeza', 26.8],
                    {
                        name: 'Enojo',
                        y: 12.8,
                        sliced: true,
                        selected: true
                    },
                    ['Ambiguedad', 8.5]
                ]
            }]
    });
}

function crea_sesion(emo) {

    if (typeof(Storage) !== "undefined")
    {
        // Yes! localStorage and sessionStorage support!
        // Some code.....
        //alert(emo);
        sessionStorage.emo = emo;
    }
    else
    {
        // Sorry! No web storage support..
        alert("Navegador no soportado");
    }
}